package com.snake.springboot.custom.service.assemble.base;


import com.snake.springboot.custom.api.model.points.PointsChangeModel;
import com.snake.springboot.custom.api.model.points.PointsChangeType;
import com.snake.springboot.custom.dao.mybatis.entity.base.CustPointsExpireDO;
import org.snake.common.code.SerialNumberGeneratorFactory;
import org.snake.common.date.DateUtil;

import java.util.Calendar;
import java.util.Date;

/**
 * <p>积分过期回收组装器
 * 类{@code CustPointsExpireAssmble} </br>
 * 创建时间2025/5/6 11:12
 * @author yangxt
 * @see
 */
public class CustPointsExpireAssemble {

    public static CustPointsExpireDO toExpireDO(PointsChangeModel model) {
        CustPointsExpireDO expireDO = new CustPointsExpireDO();
        expireDO.setChangeType(model.getChangeType());
        expireDO.setCustPointsExpireId(SerialNumberGeneratorFactory.buildId4Bean());
        expireDO.setPoints(model.getChangePoints());
        expireDO.setCustomId(model.getCustomId());
        Calendar ca = Calendar.getInstance();
        ca.setTime(new Date());
        ca.add(Calendar.YEAR,1);
        Date time = ca.getTime();
        expireDO.setExpireTime(DateUtil.formatDateTime(time));
        return expireDO;
    }

    public static PointsChangeModel toModel(CustPointsExpireDO expireDO) {
        PointsChangeModel model = new PointsChangeModel();
        model.setParentId(expireDO.getCustPointsExpireId());
        model.setChangePoints(expireDO.getPoints().subtract(expireDO.getPointsUsed()));
        model.setRemark("过期");
        model.setChangeType(PointsChangeType.EXPIRE.getChangeType());
        model.setCustomId(expireDO.getCustomId());
        return model;
    }
}
